home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLMENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  8.2 KB  |  250 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                             /*----------------*
  9.                              *   CPPLMENU.C   *
  10.                              * Main menu Mgr  *
  11.                              *----------------*/
  12.  
  13.  /* Included Files */
  14.  # include <stdio.h>
  15.  # include <io.h>
  16.  # include <dos.h>
  17.  # include <fcntl.h>
  18.  # include <bios.h>
  19.  # include <stdlib.h>
  20.  # include <conio.h>
  21.  
  22.  /* Global Variables */
  23.  extern int bm,i,j,k,l,m,n,t,x,x1,x2,xm,y,y1,y2,ym,z,menu0,return0;
  24.  extern int colour1,colour2,colour3,colour4,colour5;
  25.  extern unsigned char c0,c1,trashcan[];
  26.  
  27.  /*---------------*
  28.   * DISPLAY MENU0 *
  29.   *---------------*/
  30.   void display_menu0()
  31.     {
  32.       /* We display the first menu line and today's date     */
  33.       /* This will be permanently displayed                  */
  34.       /* To avoid mouse traces, we hide it and show it after */
  35.       hide_the_mouse();
  36.       textattr(colour1);                 clrscr();
  37.       textattr(colour2);                 gotoxy(1,1);
  38.       cputs(" Files    Menu2   Menu3   Menu4   Menu5   Menu6   Menu7   Menu8   Config.  Help ");
  39.       /* Display the system date in the upper-right corner */
  40.       get_date_text_format();
  41.       gotoxy(69,2);                    cputs("╔══════════╗");
  42.       gotoxy(69,3);                    cputs("║          ║");
  43.       gotoxy(69,4);                    cputs("╚══════════╝");
  44.       gotoxy(71,3);                    cputs(trashcan);
  45.       /* We display the letter keys in red over lightgrey */
  46.       textattr(116);
  47.       gotoxy(2,1);                     cputs("F");
  48.       gotoxy(15,1);                    cputs("2");
  49.       gotoxy(23,1);                    cputs("3");
  50.       gotoxy(31,1);                    cputs("4");
  51.       gotoxy(39,1);                    cputs("5");
  52.       gotoxy(47,1);                    cputs("6");
  53.       gotoxy(55,1);                    cputs("7");
  54.       gotoxy(63,1);                    cputs("8");
  55.       gotoxy(67,1);                    cputs("C");
  56.       gotoxy(76,1);                    cputs("H");
  57.       show_the_mouse();
  58.     }
  59.  /*----------------*
  60.   * GET THE MOUSE0 *
  61.   *----------------*/
  62.   int get_the_mouse0()
  63.     {
  64.       /* If we choose with the mouse */
  65.       /*  Only  available for menu 0 */
  66.       if((ym>0)&&(ym<3)){
  67.     if((xm>0)&&(xm<10)){
  68.           /* Choice Files menu */
  69.       return(1);
  70.     }
  71.     if((xm>9)&&(xm<18)){
  72.           /* Choice menu2 */
  73.       return(2);
  74.     }
  75.     if((xm>17)&&(xm<26)){
  76.           /* Choice menu3 */
  77.       return(3);
  78.     }
  79.     if((xm>25)&&(xm<34)){
  80.           /* Choice menu4 */
  81.       return(4);
  82.     }
  83.     if((xm>33)&&(xm<42)){
  84.           /* Choice menu5 */
  85.       return(5);
  86.     }
  87.     if((xm>41)&&(xm<50)){
  88.           /* Choice menu6 */
  89.       return(6);
  90.     }
  91.     if((xm>49)&&(xm<58)){
  92.           /* Choice menu7 */
  93.       return(7);
  94.     }
  95.     if((xm>57)&&(xm<66)){
  96.           /* Choice menu8 */
  97.       return(8);
  98.     }
  99.     if((xm>65)&&(xm<74)){
  100.           /* Choice Configuration menu*/
  101.       return(9);
  102.     }
  103.     if((xm>73)&&(xm<=80)){
  104.           /* Choice help menu */
  105.       return(10);
  106.     }
  107.       }
  108.       /* If the co-ordinates does not match we erase the menu */
  109.       return(0);
  110.     }
  111.  /*--------------------*
  112.   * GET SPECIAL MENU00 *
  113.   *--------------------*/
  114.   int get_special_menu00()
  115.     {
  116.       if(c1==77){
  117.         /* Right arrow */
  118.     if(menu0<10)                    menu0++;
  119.     else                            menu0=1;
  120.     return(1);
  121.       }
  122.       if(c1==75){
  123.         /* Left arrow */
  124.     if(menu0>1)                    menu0--;
  125.     else                           menu0=10;
  126.     return(1);
  127.       }
  128.       if(c1==33){
  129.         /* Alt + F = Call menu1 */
  130.     menu0=1;                       return(1);
  131.       }
  132.       if(c1==121){
  133.         /* Alt + 2 = Call menu2 */
  134.     menu0=2;                       return(1);
  135.       }
  136.       if(c1==122){
  137.         /* Alt + 3 = Call menu3 */
  138.     menu0=3;                       return(1);
  139.       }
  140.       if(c1==123){
  141.         /* Alt + 4 = Call menu4 */
  142.     menu0=4;                       return(1);
  143.       }
  144.       if(c1==124){
  145.         /* Alt + 5 = Call menu5 */
  146.     menu0=5;                       return(1);
  147.       }
  148.       if(c1==125){
  149.         /* Alt + 6 = Call menu6 */
  150.     menu0=6;                       return(1);
  151.       }
  152.       if(c1==126){
  153.         /* Alt + 7 = Call menu7 */
  154.     menu0=7;                       return(1);
  155.       }
  156.       if(c1==127){
  157.         /* Alt + 8 = Call menu8 */
  158.     menu0=8;                       return(1);
  159.       }
  160.       if(c1==46){
  161.         /* Alt + C = Call menuC */
  162.     menu0=9;                       return(1);
  163.       }
  164.       if(c1==35){
  165.         /* Alt + H = Call menuH */
  166.     menu0=10;                      return(1);
  167.       }
  168.       return(0);
  169.     }
  170.  /*------------------------*
  171.   * DISPLAY SELECTED MENU0 *
  172.   *------------------------*/
  173.   void display_selected_menu0()
  174.     {
  175.     /* We display what was on the screen before the menu call */
  176.       restore_screen();
  177.       if(menu0==1)                     display_menu1();
  178.       if(menu0==2)                     display_menu2();
  179.       if(menu0==3)                     display_menu3();
  180.       if(menu0==4)                     display_menu4();
  181.       if(menu0==5)                     display_menu5();
  182.       if(menu0==6)                     display_menu6();
  183.       if(menu0==7)                     display_menu7();
  184.       if(menu0==8)                     display_menu8();
  185.       if(menu0==9)                     display_menu9();
  186.       if(menu0==10)                    display_menu10();
  187.     }
  188.  /*--------------*
  189.   * MENU CHOICE0 *
  190.   *--------------*/
  191.   void menu_choice0()
  192.     {
  193.       /* We do nothing until a key is pressed */
  194.       /* or we pressed a mouse button.        */
  195.       while(1){
  196.     if(kbhit()){
  197.           /* If we pressed a key */
  198.       c1=getch();
  199.       if((c1==65)||(c1==97)){
  200.           /* Only direct call allowed to get the help */
  201.         i=10;                      break;
  202.       }
  203.       if(c1==0){
  204.             /* Key coded on 2 bytes, we get the second byte */
  205.             c1=getch();                get_special_menu00();
  206.         i=menu0;                   break;
  207.       }
  208.     }
  209.         /* Else we test the mouse */
  210.         get_mouse_state();
  211.     if(bm==1){
  212.           /* We pressed a mouse button */
  213.           i=get_the_mouse0();     break;
  214.     }
  215.       }
  216.       /* We translate the result and send it back */
  217.       menu0=i;
  218.     }
  219.  /*-------------------*
  220.   * MAIN MENU MANAGER *
  221.   *-------------------*/
  222.   void main_menu_manager()
  223.     {
  224.       /* We save the screen before displaying the menu because */
  225.       /* we will restore the whole screen but the first line   */
  226.       display_menu0();                 hide_the_mouse();
  227.       /* During the saving we hide the mouse to avoid traces */
  228.       /* in case of mouse moving                             */
  229.       save_screen();              show_the_mouse();
  230.       return0=0;
  231.       while(1){
  232.       /* When we changed of menu by an arrow, we do not ask for a new */
  233.       /* choice. */
  234.         if(return0!=-2)                menu_choice0();
  235.         display_selected_menu0();        return0=0;
  236.         if(menu0==1)                   return0=menu_manager1();
  237.         if(menu0==2)                   return0=menu_manager2();
  238.         if(menu0==3)                   return0=menu_manager3();
  239.         if(menu0==4)                   return0=menu_manager4();
  240.         if(menu0==5)                   return0=menu_manager5();
  241.         if(menu0==6)                   return0=menu_manager6();
  242.         if(menu0==7)                   return0=menu_manager7();
  243.         if(menu0==8)                   return0=menu_manager8();
  244.         if(menu0==9)                   return0=menu_manager9();
  245.         if(menu0==10)                  return0=menu_manager10();
  246.         if(return0==-1)                return;
  247.       }
  248.     }
  249. /* End of the Module */ /*-----------------------*/
  250.